package com.neusoft.elmboot.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.elmboot.po.DeliveryAddress;
import com.neusoft.elmboot.service.DeliveryAddressService;

@RestController
@RequestMapping("/DeliveryAddress")
public class DeliveryAddressController {

	@Autowired
	private DeliveryAddressService deliveryAddressService;
	
	@RequestMapping(value = "/userId/{userId}",method = RequestMethod.GET)
	public List<DeliveryAddress> listDeliveryAddressByUserId(@PathVariable("userId") String userId) throws Exception{
		return deliveryAddressService.listDeliveryAddressByUserId(userId);
	} 
	
	@RequestMapping(value = "/daId/{daId}",method = RequestMethod.GET)
	public DeliveryAddress getDeliveryAddressById(@PathVariable("daId") Integer daId) throws Exception{
		return deliveryAddressService.getDeliveryAddressById(daId);
	} 
	
	@RequestMapping(method = RequestMethod.POST)
	public int saveDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
		return deliveryAddressService.saveDeliveryAddress(deliveryAddress);
	} 
	
	@RequestMapping(method = RequestMethod.PUT)
	public int updateDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
		return deliveryAddressService.updateDeliveryAddress(deliveryAddress);
	} 
	
	@RequestMapping(value = "/daId/{daId}", method = RequestMethod.DELETE)
	public int removeDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
		return deliveryAddressService.removeDeliveryAddress(deliveryAddress.getDaId());
	} 
}
